package com.yjm.tb.protocol.parsers;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.yjm.tb.model.TbTopic;
import com.yjm.tb.protocol.types.TbTopicListBean;


public class TbTopicListParser extends AbstractParser<TbTopicListBean> {

	@Override
	protected TbTopicListBean parseInner(String jsonData) {

		TbTopicListBean problemListType = new TbTopicListBean();
		List<TbTopic> problemList = problemListType.getProblemList();
		try {
			Log.i("test", jsonData);
			JSONArray jsonObjects = new JSONArray(jsonData);

			for (int i = 0; i < jsonObjects.length(); i++) {
				TbTopic problem = new TbTopic();
				JSONObject jsonObject = (JSONObject) jsonObjects.opt(i);

				problem.setId(jsonObject.getInt("id"));
				problem.setType(jsonObject.getInt("type"));
				problem.setLevel(jsonObject.getInt("level"));
				problem.setRate(jsonObject.getInt("content_score"));
				problem.setContent(jsonObject.getString("content"));

				problemList.add(problem);

			}
		} catch (JSONException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return problemListType;
	}

}
